var gulp = require('gulp'),
    babel = require('gulp-babel'),
    clean = require('gulp-clean'),
    gulpsync = require('gulp-sync')(gulp),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
	gutil = require('gulp-util'),
    stripDebug = require('gulp-strip-debug'),
    ngAnnotate = require('gulp-ng-annotate'),
    concat = require('gulp-concat'),
    ngHtml2Js = require("gulp-ng-html2js"),
    mincss = require('gulp-minify-css'),
    rev = require('gulp-rev'),
    collector = require('gulp-rev-collector'),
    minhtml = require('gulp-htmlmin'),
    prochtml = require('gulp-processhtml'),
    sourcemaps = require('gulp-sourcemaps');

var targetPath = 'dist/';

var managerPath = 'xcmg.parts.manager/';
var managerDist = targetPath + managerPath;

var clientPath = 'xcmg.parts.client/';
var clientDist = targetPath + clientPath;

var carrierPath = 'xcmg.parts.carrier/';
var carrierDist = targetPath + carrierPath;

/**
 * 清除文件
 **/
gulp.task('cleanManager',function(){
    return gulp.src(managerDist,{read: false})
        .pipe(clean());
})
gulp.task('cleanClient',function(){
    return gulp.src(clientDist,{read: false})
        .pipe(clean());
})
gulp.task('cleanCarrier',function(){
    return gulp.src(carrierDist,{read: false})
        .pipe(clean());
})

/**
 * 拷贝文件到发布路径
 **/
gulp.task('mvManagerAssets', function () {
    return gulp.src([managerPath + 'assets/img/**'])
        .pipe(gulp.dest(managerDist + 'assets/img'));
});

gulp.task('mvManagerLib', function () {
    return gulp.src([managerPath + 'lib/**'])
        .pipe(gulp.dest(managerDist + 'lib'));
});

gulp.task('mvManagerConfig', function () {
    return gulp.src([managerPath + 'config/config.js'])
        .pipe(gulp.dest(managerDist + 'config'));
});

/**
 * 压缩合并app data数据相关
 **/
gulp.task('mergeManagerData', function () {
    return gulp.src(
        ['data'].map(function (item) {
            return managerPath + 'config/' + item + '.js';
        }))
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(concat("app.data.js"))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(managerDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/jsdata'));
});

/**
 * 压缩合并javascript
 **/
gulp.task('buildManagerJs', function () {
    return gulp.src(
        [
            'widget/**/*.js',
            'js/controller/**/*.js',
            'js/directive/**/*.js',
            'js/filter/**/*.js',
            'js/service/**/*.js',
            'js/*.js'
        ].map(function (item) {
            return managerPath + item;
        }))
		.pipe(babel({presets:['@babel/env']}))
        .pipe(ngAnnotate())
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(sourcemaps.init())
        .pipe(stripDebug())//除去js代码中的console和debugger输出
        .pipe(concat("app.min.js"))
        .pipe(uglify())
		.on('error', function(err) {
			gutil.log(gutil.colors.red('[Error]'), err.toString());
		})
        .pipe(sourcemaps.write('../maps/js'))
        .pipe(rev())
        .pipe(gulp.dest(managerDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/jsmin'));
});

/**
 * 压缩合并css
 **/
gulp.task('buildManagerCss', function () {
    return gulp.src(['common.css', 'login.css', 'app.css'].map(function (item) {
            return managerPath + 'assets/css/' + item;
        }))
        .pipe(mincss())
        .pipe(concat("app.min.css"))
        .pipe(rev())
        .pipe(gulp.dest(managerDist + 'assets/css'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/css'));
});

gulp.task('buildLoginCss', function () {
    return gulp.src(['login.css'].map(function (item) {
            return managerPath + 'assets/css/' + item;
        }))
        .pipe(mincss())
        .pipe(concat("login.min.css"))
        .pipe(rev())
        .pipe(gulp.dest(managerDist + 'assets/css'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/css'));
});

gulp.task('buildCusCss', function () {
    return gulp.src(['app.css'].map(function (item) {
            return managerPath + 'assets/css/' + item;
        }))
        .pipe(mincss())
        .pipe(concat("cus.min.css"))
        .pipe(rev())
        .pipe(gulp.dest(managerDist + 'assets/css'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/css'));
});

/**
 * 压缩处理html（视图、指令模板、组件/模态框模板、首页）
 **/
gulp.task('buildManagerHtml', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([managerPath + 'view/**/*.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(managerDist + 'view'));
});

gulp.task('buildManagerDirective', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src(['js/directive/**/*.html'].map(function (item) {
            return managerPath + item;
        }))
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-directive',
            prefix: "js/directive/"
        }))
        .pipe(concat('template.directive.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(managerDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/directive'));
});

gulp.task('buildManagerWidget', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src(['widget/**/*.html'].map(function (item) {
            return managerPath + item;
        }))
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-widget',
            prefix: "widget/"
        }))
        .pipe(concat('template.widget.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(managerDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(managerDist + 'rev/widget'));
});

gulp.task('buildManagerIndex', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([managerPath + 'index.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(managerDist));
});

gulp.task('buildManagerApp', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([managerDist + 'rev/**/*.json', managerPath + '*.html'])
        .pipe(collector({
            replaceReved: true
        }))
        .pipe(prochtml())
        .pipe(minhtml(opts))
        .pipe(gulp.dest(managerDist));
});

gulp.task('buildManager', gulpsync.sync(
    [
		'cleanManager',
        ['mvManagerAssets', 'mvManagerLib', 'mvManagerConfig', 'mergeManagerData', 'buildManagerJs', 'buildManagerCss', 'buildManagerHtml', 'buildManagerDirective', 'buildManagerWidget', 'buildManagerIndex'],
        'buildManagerApp'
    ]
));



/**
 * 拷贝文件到发布路径
 **/
gulp.task('mvClientAssets', function () {
    return gulp.src([clientPath + 'assets/img/**'])
        .pipe(gulp.dest(clientDist + 'assets/img'));
});

gulp.task('mvClientLib', function () {
    return gulp.src([clientPath + 'lib/**'])
        .pipe(gulp.dest(clientDist + 'lib'));
});

gulp.task('mvPrintPlug', function () {
    return gulp.src([clientPath + 'uploads/**'])
        .pipe(gulp.dest(clientDist + 'uploads'));
});

gulp.task('mvClientConfig', function () {
    return gulp.src([clientPath + 'config/config.js'])
        .pipe(gulp.dest(clientDist + 'config'));
});

gulp.task('mvClientI18n', function () {
    return gulp.src([clientPath + 'i18n/**'])
        .pipe(gulp.dest(clientDist + 'i18n'));
});

/**
 * 压缩合并app data数据相关
 **/
gulp.task('mergeClientData', function () {
    return gulp.src(['data', 'printData'
        ].map(function (item) {
            return clientPath + 'config/' + item + '.js';
        }))
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(concat("app.data.js"))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(clientDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(clientDist + 'rev/jsdata'));
});

/**
 * 压缩合并javascript
 **/
gulp.task('buildClientJs', function () {
    return gulp.src(
        [
            'widget/**/*.js',
            'js/controller/**/*.js',
            'js/directive/**/*.js',
            'js/filter/**/*.js',
            'js/service/**/*.js',
            'js/*.js'
        ].map(function (item) {
            return clientPath + item;
        }))
		.pipe(babel({presets:['@babel/env']}))
        .pipe(ngAnnotate())
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(sourcemaps.init())
        .pipe(stripDebug())//除去js代码中的console和debugger输出
        .pipe(concat("app.min.js"))
        .pipe(uglify())
        .pipe(sourcemaps.write('../maps/js'))
        .pipe(rev())
        .pipe(gulp.dest(clientDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(clientDist + 'rev/jsmin'));
});

/**
 * 压缩合并css
 **/
gulp.task('buildClientCss', function () {
    return gulp.src(['common.css', 'login.css', 'app.css', 'ng-img-crop.css'].map(function (item) {
            return clientPath + 'assets/css/' + item;
        }))
        .pipe(mincss())
        .pipe(concat("app.min.css"))
        .pipe(rev())
        .pipe(gulp.dest(clientDist + 'assets/css'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(clientDist + 'rev/css'));
});

/**
 * 压缩处理html（视图、指令模板、组件/模态框模板、首页）
 **/
gulp.task('buildClientHtml', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([clientPath + 'view/**/**/*.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(clientDist + 'view'));
});

gulp.task('buildClientDirective', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([clientPath + 'js/directive/**/*.html'])
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-directive',
            prefix: "js/directive/"
        }))
        .pipe(concat('template.directive.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(clientDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(clientDist + 'rev/directive'));
});

gulp.task('buildClientWidget', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([clientPath + 'widget/**/*.html'])
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-widget',
            prefix: "widget/"
        }))
        .pipe(concat('template.widget.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(clientDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(clientDist + 'rev/widget'));
});

gulp.task('buildClientIndex', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([clientPath + 'index.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(clientDist));
});

gulp.task('buildClientApp', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([clientDist + 'rev/**/*.json', clientPath + '*.html'])
        .pipe(collector({
            replaceReved: true
        }))
        .pipe(prochtml())
        .pipe(minhtml(opts))
        .pipe(gulp.dest(clientDist));
});

gulp.task('buildClient', gulpsync.sync(
    [
		'cleanClient',
        ['mvClientAssets', 'mvPrintPlug', 'mvClientLib', 'mvClientConfig', 'mvClientI18n', 'mergeClientData', 'buildClientJs', 'buildClientCss', 'buildClientHtml', 'buildClientDirective', 'buildClientWidget', 'buildClientIndex'],
        'buildClientApp'
    ]
));



/**
 * 拷贝文件到发布路径
 **/
gulp.task('mvCarrierAssets', function () {
    return gulp.src([carrierPath + 'assets/img/**'])
        .pipe(gulp.dest(carrierDist + 'assets/img'));
});

gulp.task('mvCarrierLib', function () {
    return gulp.src([carrierPath + 'lib/**'])
        .pipe(gulp.dest(carrierDist + 'lib'));
});

gulp.task('mvCarrierConfig', function () {
    return gulp.src([carrierPath + 'config/config.js'])
        .pipe(gulp.dest(carrierDist + 'config'));
});

/**
 * 压缩合并app data数据相关
 **/
gulp.task('mergeCarrierData', function () {
    return gulp.src(
        ['data'].map(function (item) {
            return carrierPath + 'config/' + item + '.js';
        }))
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(concat("app.data.js"))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(carrierDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(carrierDist + 'rev/jsdata'));
});

/**
 * 压缩合并javascript
 **/
gulp.task('buildCarrierJs', function () {
    return gulp.src(
        [
            'widget/**/*.js',
            'js/controller/**/*.js',
            'js/directive/**/*.js',
            'js/filter/**/*.js',
            'js/service/**/*.js',
            'js/*.js'
        ].map(function (item) {
            return carrierPath + item;
        }))
        .pipe(ngAnnotate())
        .pipe(jshint())
        .pipe(jshint.reporter())
        .pipe(sourcemaps.init())
        .pipe(stripDebug())//除去js代码中的console和debugger输出
        .pipe(concat("app.min.js"))
        .pipe(uglify())
        .pipe(sourcemaps.write('../maps/js'))
        .pipe(rev())
        .pipe(gulp.dest(carrierDist + 'js'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(carrierDist + 'rev/jsmin'));
});

/**
 * 压缩合并css
 **/
gulp.task('buildCarrierCss', function () {
    return gulp.src(['common.css', 'login.css', 'app.css'].map(function (item) {
            return carrierPath + 'assets/css/' + item;
        }))
        .pipe(mincss())
        .pipe(concat("app.min.css"))
        .pipe(rev())
        .pipe(gulp.dest(carrierDist + 'assets/css'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(carrierDist + 'rev/css'));
});

/**
 * 压缩处理html（视图、指令模板、组件/模态框模板、首页）
 **/
gulp.task('buildCarrierHtml', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([carrierPath + 'view/**/*.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(carrierDist + 'view'));
});

gulp.task('buildCarrierDirective', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src(['js/directive/**/*.html'].map(function (item) {
            return carrierPath + item;
        }))
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-directive',
            prefix: "js/directive/"
        }))
        .pipe(concat('template.directive.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(carrierDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(carrierDist + 'rev/directive'));
});

gulp.task('buildCarrierWidget', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src(['widget/**/*.html'].map(function (item) {
            return carrierPath + item;
        }))
        .pipe(minhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: 'template-widget',
            prefix: "widget/"
        }))
        .pipe(concat('template.widget.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(carrierDist + "js"))
        .pipe(rev.manifest())
        .pipe(gulp.dest(carrierDist + 'rev/widget'));
});

gulp.task('buildCarrierIndex', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([carrierPath + 'index.html'])
        .pipe(minhtml(opts))
        .pipe(gulp.dest(carrierDist));
});

gulp.task('buildCarrierApp', function () {
    var opts = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    return gulp.src([carrierDist + 'rev/**/*.json', carrierPath + '*.html'])
        .pipe(collector({
            replaceReved: true
        }))
        .pipe(prochtml())
        .pipe(minhtml(opts))
        .pipe(gulp.dest(carrierDist));
});

gulp.task('buildCarrier', gulpsync.sync(
    [
		'cleanCarrier',
        ['mvCarrierAssets', 'mvCarrierLib', 'mvCarrierConfig', 'mergeCarrierData', 'buildCarrierJs', 'buildCarrierCss', 'buildCarrierHtml', 'buildCarrierDirective', 'buildCarrierWidget'],
        'buildCarrierApp'
    ]
));


gulp.task('default', gulpsync.sync(['buildManager', 'buildClient']));
